<template>
  <div>
    <div v-for="(item, index) in menuList" :key="index">
      <v-contextmenu-submenu
        v-if="item.style === 'submenu'"
        :title="item.title"
      >
        <right-menu
          :menu-list="item.children"
          :callback="menuClick"
        />
      </v-contextmenu-submenu>
      <v-contextmenu-item
        v-else-if="item.style === 'divider'"
        divider
      />
      <v-contextmenu-item
        v-else-if="item.style === 'item' && item.icon"
        class="dis-flex"
        @click="menuClick(item.type)"
      >
        <div class="menu-icon-style mr-5" :class="item.icon" />
        {{ item.title }}
      </v-contextmenu-item>
      <v-contextmenu-item v-else @click="menuClick(item.type)">{{
        item.title
      }}</v-contextmenu-item>
    </div>
  </div>
</template>

<script>
/**
 * v-contextmenu 右键菜单组件二次封装
 */
export default {
  name: 'RightMenu',
  props: {
    menuList: {
      type: Array,
      required: true
    },
    callback: {
      type: Function,
      required: true
    }
  },
  methods: {
    menuClick(type) {
      this.callback(type);
    }
  }
};
</script>

<style lang="scss">
.menu-icon-style {
  width: 16px;
  height: 16px;
}
</style>
